package com.system.bill.service.impl;

import com.system.bill.bean.Bill;
import com.system.bill.repository.BillRepository;
import com.system.bill.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: BillServiceImpl
 * @description: 账单具体实现类
 * @author: Li Chuanwei
 * @date: 2023/11/12 15:40
 * @Company: Copyright [日期] by [作者或个人]
 **/

@Service
public class BillServiceImpl implements BillService {

    @Autowired
    private BillRepository billRepository;
    @Override
    public boolean saveBill(Bill bill) {
        Bill obj = billRepository.save(bill);
        if(obj != null){
            return true;
        }
        return false;
    }

    @Override
    public Bill saveGetBill(Bill bill) {
        return billRepository.save(bill);
    }

    @Override
    public boolean removeBillById(int id) {
        if (billRepository.existsById(id)) {
            billRepository.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean modifyBill(Bill bill) {
        Bill obj = billRepository.save(bill);
        if(obj != null){
            return true;
        }
        return false;
    }

    @Override
    public Bill getBillById(int id) {
        if (billRepository.existsById(id)) {
            return billRepository.getReferenceById(id);
        }
        return null;
    }

    @Override
    public List<Bill> listAllBills() {
        return billRepository.findAll();
    }
}
